// infer 可以从正在比较的类型中推断类型
type CalcFnType = (num1: number, num2: number) => number

function foo() {
  return "abc"
}

// 获取一个函数的返回值类型
type CalcReturnType = ReturnType<CalcFnType>
type FooReturnType = ReturnType<typeof foo>

// 类型体操:自己封装一个ReturnType
type MyReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : never

type CalcReturnType1 = MyReturnType<CalcFnType>
type FooReturnType1 = MyReturnType<typeof foo>

// 推断入参类型
type MyParameterType<T extends (...args: any[]) => any> = T extends (...args: infer A) => any ? A : never
type CalcReturnType2 = MyParameterType<CalcFnType>
type FooReturnType2 = MyParameterType<typeof foo>

export { }